package com.zl.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zl.common.Page;
import com.zl.dao.AgencyDao;
import com.zl.dao.WebsiteDao;
import com.zl.entity.Agency;
import com.zl.entity.NewsEntity;
import com.zl.entity.Website;
import com.zl.util.SearchUtils;

@Service
public class AgencyService {
	@Autowired
	private AgencyDao agencyDao;
	@Autowired
	private WebsiteDao websiteDao;
	public List<Agency> selectAgency(Agency agency,int pageSize,int rows){
		Page page = new Page(pageSize,rows);
		List<Agency> list = agencyDao.selectAgency(agency, new RowBounds(page.getStartOfPage(), rows));
		return list;
	}
	
	public Agency selectAgencyById(String id){
		return agencyDao.getAgencyById(id);
	}
	
	public List<NewsEntity> getNewsByAgencyId(String id){
		List<NewsEntity> newslist = new ArrayList<NewsEntity>();
		List<Website> weblist =  websiteDao.selectWebsiteByAgencyId(id);
		if(weblist.size()>0){
			newslist = SearchUtils.selectEsByWz(weblist.get(0).getId());
		}
		return newslist;
	}
}
